package rbac.test;

import com.pandawork.core.bean.BeanFactory;
import com.pandawork.core.bean.SpringManager;

/**
 * RBAC Spring bean factory.
 * 
 * @author Huadi
 */
public class RbacFactory {

	// ---=== Fields ===--- //
	private static BeanFactory beanFactory;

	private static final String configFilePath = "mainApplicationContext.xml";

	// 内部静态类, 负责以懒汉式实现单例.
	private static class SingletonHolder {
		static RbacFactory rbacFactory = new RbacFactory();
	}

	// ---=== Constructor ===--- //
	// 私有构造函数, 使用工厂方法获得变量.
	private RbacFactory() {
		beanFactory = new SpringManager(configFilePath, RbacFactory.class);
	}

	// ---=== Methods ===--- //
	public static RbacFactory getInstance() {
		return SingletonHolder.rbacFactory;
	}

	public <T> T getBean(String name) {
		return beanFactory.getBean(name);
	}
}
